<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>票品信息管理</title>
<%@include file="../../header.jsp" %>
<!-- ueditor -->
<script type="text/javascript" src="/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="/ueditor/ueditor.all.js"></script>

<!-- my97datepicker -->
<script type="text/javascript" src="/My97DatePicker/WdatePicker.js"></script>

<!-- jquery fileupload -->
<script type="text/javascript" src="/js/vendor/jquery.ui.widget.js"></script>  
<script type="text/javascript" src="/js/jquery.iframe-transport.js"></script>  
<script type="text/javascript" src="/js/jquery.fileupload.js"></script>
<link rel="stylesheet" href="/css/jquery.fileupload.css">
<script type="text/javascript">
	var pageNumber = 1;
	function turnpage(page) {
		pageNumber = page;
		query(page);
	}
	
	function query(page) {
		$.ajax({
			url:"/ticket/shelf/page.htm",
			type:"post",
			data:$("#onsale-ticket-query-form").serialize()+"&pageNo="+page,
			dataType:"html"
		}).done(function(data){
			$("#onsale-ticket-table").html(data);
		})
	}
	
	function selectScene() {
		var modal = $.bmodal({
			title:"选择景区",
			url:"/scene/dialog.htm",
			buttons:[{
				text:"保存",
				click:function() {
					var checkedScene = $("input[name='sceneId']:checked");
					var sceneId = checkedScene.val();
					var sceneName = checkedScene.parent().next().text();
					$("#onsale-ticket-query-form").find("input[name='scenic_id']").val(sceneId);
					$("#scene-name-display").val(sceneName);
					modal.modal("hide");
				}
			},{
				text:"关闭",
				click:function() {
					modal.modal("hide");
				}
			}]
		})
	}
	
	function addview() {
		$(".shelf-index-div:eq(1)").reload();
		$(".shelf-index-div").hide();
		$(".shelf-index-div:eq(1)").show();
	}
	
	function remove() {
		
	}
	
	function viewRelatedTickets(id) {
		var modal = $.bmodal({
			title:"查看关联票",
			url:"/ticket/shelf/relateTicketsDialog.htm?id="+id,
			buttons:[{
				text:"关闭",
				click:function() {
					modal.modal("hide");
				}
			}]
		})
	}
	
	function viewRelatedLines() {
		
	}
	
	function selectTicket() {
		var modal = $.bmodal({
			title:"选择票品",
			url:"/ticket/dialog.htm",
			buttons:[{
				text:"保存",
				click:function() {
					var showType = $("#ticket-dialog-div").css("display");
					if(showType=="block") {
						var checkedTicket = $("#ticket-shelf-table").find("input[name='ticketId']:checked");
						if(checkedTicket[0]==undefined)
							alert("请选择票！！");
						else {
							var ticketId = checkedTicket.val();
							var ticketName = checkedTicket.parent().next().text();
							$("#ticket-name-display").val(ticketName);
							$("#ticket-name-display").next().val(ticketId);
							modal.modal("hide");
							$("#ticket-view-div").load("/ticket/shelf/ticketDetail.htm?id="+ticketId);
						}
					} else if(showType=="none") {
						var checkedScene = $("input[name='sceneId']:checked");
						if(checkedScene[0]==undefined)
							alert("请选择景区！！");
						else {
							var sceneId = checkedScene.val();
							var sceneName = checkedScene.parent().next().text();
							$("#ticket-dialog-scene-name-display").val(sceneName);
							$("#ticket-dialog-scene-name-display").next().val(sceneId);
							$("#ticket-scene-dialog-div").hide();
							$("#ticket-dialog-div").show();
						}
					}
				}
			},{
				text:"关闭",
				click:function() {
					modal.modal("hide");
				}
			}]
		})
	}
	
	function shelfTicketConfirm() {
		var checks = $("#shelf-ticket-table").find("input[type='checkbox']");
		var ticketId = "";
		var count = 0;
		$.each(checks, function(i, n){
			if(n.checked==true) {
				ticketId = n.value;
				count++;
			}
		})
		if(count>1) alert("只能选择一张票！！");
		else {
			$(".shelf-index-div").hide();
			$(".shelf-index-div:eq(1)").show();
			$("#ticket-shelf-div").load("/ticket/shelf/loadticket.htm?id="+ticketId);
		}
	}
	
	function saveShelf() {
		/* $(".shelf-index-div:eq(0)").reload();
		$(".shelf-index-div").hide();
		$(".shelf-index-div:eq(0)").show(); */
		
		var ticketId = $("#ticket-name-display").next().val();
		if(ticketId==null||ticketId=="")
			alert("请选择票！！");
		else {
			var policys = $("#ticket-shelf-form").find("input[tag='promotionPolicy']");
			var array = new Array();
			$.each(policys, function(i, n){
				if(n.checked) {
					var policy = {};
					policy.dictionaryid = $(n).val();
					policy.promotionBaseData = $(n).next().val();
					policy.promotionData = $(n).next().next().val();
					array.push(policy);
				}
			})
			
			$.ajax({
				url:"/ticket/shelf/save.htm",
				type:"post",
				data:$("#ticket-shelf-form").serialize()+"&ticketPromotionPolicyUse="+JSON.stringify(array)
					+"&ticketInfoId="+ticketId,
				dataType:"json"
			}).done(function(data){
				alert(data.msg);
				if(data.isSuccess) {
					$(".shelf-index-div").hide();
					$(".shelf-index-div:eq(0)").show();
					window.location = window.location;
				}
			})
		}
	}
	
	function saveShelfReturn() {
		$(".shelf-index-div").hide();
		$(".shelf-index-div:eq(0)").show();
	}
	
	function changeShelfStatus(id, isok) {
		var title = isok==1?"下架":"上架";
		if(window.confirm("确定要"+title+"么？")) {
			$.ajax({
				url:"/ticket/shelf/changeShelfStatus.htm?id="+id+"&isok="+isok,
				dataType:"json"
			}).done(function(data){
				alert(data.msg);
				if(data.isSuccess)
					query(pageNumber);
			})
		}
	}
	
    $(function () { 
      //$('#ticket a:last').tab('show');//初始化显示哪个tab 
    	
      	$(document).on('click', '.taba', function(e) {
        	e.preventDefault();//阻止a链接的跳转行为 
        	$(this).tab('show');//显示当前选中的链接及关联的content 
        });
      
      	/* $(document).on("mouseenter", 'ul.gallery li', function () {
            $('img', this).fadeToggle(1000);
            $(this).find('.gallery-controls').remove();
            $(this).append('<div class="well gallery-controls">' +
                '<p><a href="javascript:;" class="gallery-delete btn"><i class="glyphicon glyphicon-remove"></i></a></p>' +
                '</div>');
            $(this).find('.gallery-controls').stop().animate({'margin-top': '-1'}, 400);
        }); */
        
      	/* $('.thumbnails').on('click', '.gallery-delete', function (e) {
            e.preventDefault();
            //get image id
            //alert($(this).parents('.thumbnail').attr('id'));
            //$(this).parents('.thumbnail').fadeOut();
            $(this).parents('.thumbnail').remove();
        });
      	
        $(document).on("mouseleave", 'ul.gallery li', function () {
            $('img', this).fadeToggle(1000);
            $(this).find('.gallery-controls').stop().animate({'margin-top': '-30'}, 200, function () {
                $(this).remove();
            });
        }); */
      
      	$("#ticket-img-upload").fileupload({  
    	    url:"/common/upload.htm",//文件上传地址，当然也可以直接写在input的data-url属性内  
    	    formData:{type:"ticket"},//如果需要额外添加参数可以在这里添加  
    	    done:function(e,data){  
    	        //done方法就是上传完毕的回调函数，其他回调函数可以自行查看api  
    	        //注意result要和jquery的ajax的data参数区分，这个对象包含了整个请求信息  
    	        //返回的数据在result.result中，假设我们服务器返回了一个json对象  
    	        //console.log(JSON.stringify(result.result)); 
    	        var ret = eval("("+data.result+")");
    	        if(ret.isSuccess) {
    	        	var li = "<li class='thumbnail'><a style='background:url("+ret.json.url+")'><img"+
                    "class='grayscale' src='"+ret.json.url+"'></a></li>";
    	        	$(".thumbnails").append(li);
    	        } 
    	    }  
    	}) 
    	
    	$("#savebtn").click(function() {
    		//ajax
    		/* $("#edit-ticket-tab").parent().remove();
    		$("#list-ticket-tab").tab("show"); */
    	})
    	
    	//var ue1 = UE.getEditor('desc_editor',{initialFrameWidth:900});
    	//var ue2 = UE.getEditor('buynote_editor',{initialFrameWidth:900});
    }) 
</script>
</head>
<body>
    <div class="shelf-index-div"><jsp:include page="list.jsp"/></div>
    <div class="shelf-index-div" style="display:none;" url="/ticket/shelf/addview.htm"></div>
    <div class="shelf-index-div" style="display:none;" url="/ticket/shelf/ticket.htm"></div>
    <div class="shelf-index-div" style="display:none;" url="/ticket/shelf/line.htm"></div>
    <div class="shelf-index-div" style="display:none;"></div>
    
</body>
</html>